<!doctype html>
<html xml:lang="zh-CN" lang="zh-CN">

<head>
        <link rel="canonical" href="https://v2rayjichang.github.io/news/article-83404.htm" />
    <!--====== Required meta tags ======-->
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Spring Security核心类详解</title>
        <meta name="description" content="Spring Security是什么 Spring Security 是一种基于 Spring AOP 和 Servlet 过滤器 Filter 的安全框架，它提供了全面的安全解决方案，提供在 Web" />
        <link rel="icon" href="/assets/website/img/surfboardnode/favicon.ico" type="image/x-icon"/>

    <meta name="author" content="V2ray免费机场 节点订阅中文官网">
    <meta property="og:type" content="article" />
    <meta property="og:url" content="https://v2rayjichang.github.io/news/article-83404.htm" />
    <meta property="og:site_name" content="V2ray免费机场 节点订阅中文官网" />
    <meta property="og:title" content="Spring Security核心类详解" />
    <meta property="og:image" content="https://v2rayjichang.github.io/uploads/20240709-1/ab9c50af26d6909a5d79c0c2ab0176cc.webp" />
        <meta property="og:release_date" content="2025-03-28T09:56:12" />
    <meta property="og:updated_time" content="2025-03-28T09:56:12" />
        <meta property="og:description" content="Spring Security是什么 Spring Security 是一种基于 Spring AOP 和 Servlet 过滤器 Filter 的安全框架，它提供了全面的安全解决方案，提供在 Web" />
        
    <meta name="applicable-device" content="pc,mobile" />
    <meta name="renderer" content="webkit" />
    <meta name="force-rendering" content="webkit" />
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta name="robots" content="max-image-preview:large" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Spring Security核心类详解">
    <meta name="format-detection" content="telephone=no">

    <link rel="dns-prefetch" href="https:/www.googletagmanager.com">
    <link rel="dns-prefetch" href="https://www.googleadservices.com">
    <link rel="dns-prefetch" href="https://www.google-analytics.com">
    <link rel="dns-prefetch" href="https://pagead2.googlesyndication.com">
    <link rel="dns-prefetch" href="https://cm.g.doubleclick.net">
    
    <!--====== Bootstrap css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/bootstrap.min.css">
    <!--====== Slick css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/slick.css">
    <!--====== Magnific Popup css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/magnific-popup.css">
    <!--====== Line Icons css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/LineIcons.css">
    <!--====== Default css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/default.css">
    <!--====== Style css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/style.css">
    <!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LMZ4WN7LCM"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-LMZ4WN7LCM');
</script>
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3332997411212854"
     crossorigin="anonymous"></script>
</head>

<body data-page="detail">
    <!--====== HEADER ONE PART START ======-->
    <header class="header-area">
        <div class="navbar-area navbar-one navbar-transparent">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <nav class="navbar navbar-expand-lg">
                    <a class="navbar-brand" href="/">
                                        <span>
                        V2ray免费机场                    </span>
                                        </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarOne" aria-controls="navbarOne" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="toggler-icon"></span>
                        <span class="toggler-icon"></span>
                        <span class="toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse sub-menu-bar" id="navbarOne">
                        <ul class="navbar-nav m-auto">
                                                        <li class="nav-item">
                                <a href="/">首页</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/free-nodes/">免费节点</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/paid-subscribe/">推荐机场</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/news/">新闻资讯</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/client.htm">客户端</a>
                            </li>
                                                    </ul>
                    </div>
                </nav> <!-- navbar -->
            </div>
        </div> <!-- row -->
    </div> <!-- container -->
</div>
        <div id="home" class="header-content-area d-flex align-items-center list" style="height:450px;">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="header-wrapper">
                            <div class="header-content">
                                <h1 class="header-title">Spring Security核心类详解</h1>
                                <p class="text nav">
                                    <a href="/">首页</a> / <a href="/news/">新闻资讯</a> / <span>正文</span>
                                </p>
                            </div> <!-- header content -->
                            <div class="header-image d-none d-lg-block">
                                <div class="image">
                                    <img src="/assets/website/img/surfboardnode/header.png" alt="Header">
                                </div>
                            </div>
                        </div>
                    </div>
                </div> <!-- row -->
            </div> <!-- container -->
            <div class="header-shape">
                <img src="/assets/website/img/surfboardnode/header-shape.svg" alt="shape">
            </div> <!-- header-shape -->
        </div> <!-- header content area -->
    </header>
    <!--====== HEADER ONE PART ENDS ======-->
    <!--====== ABOUT THREE PART START ======-->
    <section id="about" class="about-area pt-70 pb-100">
        <div class="container">
            <div class="row">
                <div class="col-md-9">
                                    <input type="hidden" id="share-website-info" data-name="Clash Node官网订阅站" data-url="https://clashnode.github.io">
                  				  				  				<div id="content_views" class="markdown_views prism-dracula"> <h2><a id="Spring_Security_0" rel="nofollow"></a>Spring Security是什么</h2> <p>Spring Security 是一种基于 Spring AOP 和 Servlet 过滤器 Filter 的安全框架，它提供了全面的安全解决方案，提供在 Web 请求和方法调用级别的用户鉴权和权限控制。</p> <p>Web 应用的安全性通常包括两方面：<strong>用户认证（Authentication）和用户授权（Authorization）。</strong></p> <ul> <li> <p>用户认证指的是验证某个用户是否为系统合法用户，也就是说用户能否访问该系统。用户认证一般要求用户提供用户名和密码，系统通过校验用户名和密码来完成认证。</p> </li> <li> <p>用户授权指的是验证某个用户是否有权限执行某个操作。</p> </li> </ul> <h2><a id="_12" rel="nofollow"></a>核心组件</h2> <h2><a id="SecurityContextHolder_14" rel="nofollow"></a>SecurityContextHolder、</h2> <p>SecurityContextHolder 是最基本的对象，它负责存储当前安全上下文信息。即保存着当前用户是什么，是否已经通过认证，拥有哪些权限。。。等等。SecurityContextHolder默认使用<strong>ThreadLocal</strong>策略来存储认证信息，意味着这是一种与线程绑定的策略。在Web场景下的使用Spring Security，在用户登录时自动绑定认证信息到当前线程，在用户退出时，自动清除当前线程的认证信息。</p> <pre><code>Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();  if (principal instanceof UserDetails) { String username = ((UserDetails)principal).getUsername(); } else { String username = principal.toString(); }</code></pre> <h2><a id="SecurityContext_28" rel="nofollow"></a>SecurityContext</h2> <p>安全上下文，主要持有Authentication对象，如果用户未鉴权，那Authentication对象将会是空的。该示例可以通过SecurityContextHolder.getContext静态方法获取</p> <h2><a id="Authentication_32" rel="nofollow"></a>Authentication</h2> <ul> <li>getAuthorities，权限列表,通常是代表权限的字符串列表；</li> <li>getCredentials，密码信息,由用户输入的密码凭证，认证之后会移出，来保证安全性；</li> <li>getDetails，细节信息，Web应用中一般是访问者的ip地址和sessionId；</li> <li>getPrincipal, 最重要的身份信息，一般返回UserDetails的实现类；</li> </ul> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220602/7fc138d2d0f9f8d82e3833192dc6f3c0.jpg" alt="Spring Security核心类详解"></p> <h2><a id="UserDetails__UserDetailsService_41" rel="nofollow"></a>UserDetails 和 UserDetailsService</h2> <h2><a id="AuthenticationManager_45" rel="nofollow"></a>AuthenticationManager</h2> <p>AuthenticationManager接口只包含一个方法，那就是认证，它是认证相关的核心接口，也是发起认证的出发点。实际业务中可能根据不同的信息进行认证，所以Spring推荐通过实现AuthenticationManager接口来自定义自己的认证方式.Spring提供了一个默认的实现，ProviderManager。</p> <h2><a id="ProviderManager_49" rel="nofollow"></a>ProviderManager</h2> <p>其实ProviderManager不是自己处理身份验证请求，它将委托给配置的AuthenticationProvider列表，按照顺序进行依次认证，每个provider都会尝试认证，或者通过简单地返回null来跳过验证。如果所有实现都返回null，那么ProviderManager将抛出一个ProviderNotFoundException</p> <h2><a id="AuthenticationProvider_53" rel="nofollow"></a>AuthenticationProvider</h2> <p>AuthenticationProvider接口提供了两个方法，一个是真正的认证，另一个是满足什么样的身份信息才进行如上认证。</p> <h2><a id="httpsimgblogcsdnnet20180611154036239watermark2textaHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzI5ODk5MjY1font5a6L5L2Tfontsize400fillI0JBQkFCMAdissolve70_57" rel="nofollow"></a><img decoding="async" src="http://img.555519.xyz/uploads3/20220602/e2243abaae0ed69a54ebf65dfc44b99c.jpg" alt="Spring Security核心类详解"></h2> <p>认证完成后, AuthenticationManager 将会返回该认证对象(UsernamePasswordAuthenticationToken)返回给过滤器</p> <h2><a id="_65" rel="nofollow"></a>认证流程：</h2> <ol> <li>用户提交用户名、密码被SecurityFilterChain中的<code>UsernamePasswordAuthenticationFilter</code> 过滤器获取到，封装为请求Authentication，通常情况下是<code>UsernamePasswordAuthenticationToken</code>这个实现类。</li> <li>然后过滤器将Authentication提交至<code>认证管理器(AuthenticationManager)</code>进行认证</li> <li>认证成功后， AuthenticationManager 身份管理器返回一个被填充满了信息的(包括上面提到的权限信息， 身份信息，细节信息，但密码通常会被移除)<code>Authentication</code> 实例。</li> <li><code>SecurityContextHolder 安全上下文容器</code>将第3步填充了信息的 Authentication ，通过<code>SecurityContextHolder.getContext().setAuthentication(...)</code>方法，设置到其中。可以看出AuthenticationManager接口(认证管理器)是认证相关的核心接口，也是发起认证的出发点，它 的实现类为ProviderManager。而Spring Security支持多种认证方式，因此ProviderManager维护着一个<br /> List 列表，存放多种认证方式，最终实际的认证工作是由<code>AuthenticationProvider</code>完成的。咱们知道web表单的对应的AuthenticationProvider实现类为<code>DaoAuthenticationProvider</code>，它的内部又维护着一个<code>UserDetailsService</code>负责UserDetails的获取。最终<code>AuthenticationProvider</code>将UserDetails填充至Authentication。</li> </ol> <p>参考文章：</p> <p><a href="http://www.m6000.cn/wp-content/themes/begin%20lts/inc/go.php?url=https://blog.csdn.net/sinat_29899265/article/details/80653167"  rel="nofollow">https://blog.csdn.net/sinat_29899265/article/details/80653167</a></p> <p><a href="http://www.m6000.cn/wp-content/themes/begin%20lts/inc/go.php?url=https://blog.csdn.net/cold___play/article/details/105199253?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-2&amp;spm=1001.2101.3001.4242"  rel="nofollow">https://blog.csdn.net/cold___play/article/details/105199253?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-2&amp;spm=1001.2101.3001.4242</a></p> </div> 			                <div class="clearfix"></div>
                <div class="col-md-12 mt-5">
                                        <p>上一个：<a href="/news/article-82860.htm">济南宠物领养中心在哪个位置（济南宠物领养济南宠物赠送）</a></p>
                                        <p>下一个：<a href="/news/article-83405.htm">宠物医院猫咪打疫苗多少钱（宠物医院给猫打的疫苗是什么）</a></p>
                                    </div>
                                </div>
                <div class="col-md-3">
                    <div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">热门文章</h3>
    </div>
    <div class="panel-body">
        <ul class="p-0 x-0" style="list-style: none;margin: 0;padding: 0;">
                        <li class="py-2"><a href="/news/article-84856.htm" title="全国宠物领养平台可信吗现在（全国宠物领养中心官网）">全国宠物领养平台可信吗现在（全国宠物领养中心官网）</a></li>
                        <li class="py-2"><a href="/free-nodes/2025-3-27-clash-v2ray-ss-ssr.htm" title="免费VPN翻墙推荐 | 3月27日21.7M/S|免费Clash/SSR/Shadowrocket/V2ray订阅节点地址分享">免费VPN翻墙推荐 | 3月27日21.7M/S|免费Clash/SSR/Shadowrocket/V2ray订阅节点地址分享</a></li>
                        <li class="py-2"><a href="/news/article-84141.htm" title="windows kubectl安装配置">windows kubectl安装配置</a></li>
                        <li class="py-2"><a href="/free-nodes/2025-3-30-node-share.htm" title="V2ray免费机场 | 3月30日21.4M/S|免费SSR/Clash/V2ray/Shadowrocket订阅节点地址分享">V2ray免费机场 | 3月30日21.4M/S|免费SSR/Clash/V2ray/Shadowrocket订阅节点地址分享</a></li>
                        <li class="py-2"><a href="/news/article-83405.htm" title="宠物医院猫咪打疫苗多少钱（宠物医院给猫打的疫苗是什么）">宠物医院猫咪打疫苗多少钱（宠物医院给猫打的疫苗是什么）</a></li>
                        <li class="py-2"><a href="/news/article-82860.htm" title="济南宠物领养中心在哪个位置（济南宠物领养济南宠物赠送）">济南宠物领养中心在哪个位置（济南宠物领养济南宠物赠送）</a></li>
                        <li class="py-2"><a href="/news/article-84142.htm" title="中国十大宠物粮上市公司排名 卖宠物粮食的上市公司">中国十大宠物粮上市公司排名 卖宠物粮食的上市公司</a></li>
                        <li class="py-2"><a href="/free-nodes/2025-3-29-free-high-speed-nodes.htm" title="V2ray免费机场 | 3月29日21.9M/S|免费SSR/Shadowrocket/Clash/V2ray订阅节点地址分享">V2ray免费机场 | 3月29日21.9M/S|免费SSR/Shadowrocket/Clash/V2ray订阅节点地址分享</a></li>
                        <li class="py-2"><a href="/news/article-83404.htm" title="Spring Security核心类详解">Spring Security核心类详解</a></li>
                        <li class="py-2"><a href="/free-nodes/2025-3-28-free-subscribe-node.htm" title="V2ray免费机场 | 3月28日23M/S|免费Shadowrocket/Clash/V2ray/SSR订阅节点地址分享">V2ray免费机场 | 3月28日23M/S|免费Shadowrocket/Clash/V2ray/SSR订阅节点地址分享</a></li>
                    </ul>
    </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">归纳</h3>
    </div>
    <div class="panel-body">
        <ul class="p-0 x-0" style="list-style: none;margin: 0;padding: 0;">
                        <li class="py-2">
                <h4><span class="badge" style="float: right;">12</span> <a href="/date/2025-03/" title="2025-03 归档">2025-03</a></h4>
            </li>
                    </ul>
    </div>
</div>

                </div>
            </div>
        </div> <!-- container -->
    </section>
    <!--====== ABOUT THREE PART ENDS ======-->
        <!--====== FOOTER PART START ======-->
    <footer id="footer" class="footer-area">
        <div class="footer-copyright">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="copyright text-center">
                            <p>
                                <a href="/">首页</a> | 
                                <a href="/free-node/">免费节点</a> | 
                                <a href="/news/">新闻资讯</a> |
                                <a href="/about-us.htm">关于我们</a> |
                                <a href="/disclaimer.htm">免责申明</a> |
                                <a href="/privacy.htm">隐私申明</a> |
                                <a href="/sitemap.xml">网站地图</a>
                            </p>
                            <p class="text">V2ray免费机场 节点订阅中文官网 版权所有 Powered by WordPress</p>
                        </div> <!-- copyright -->
                    </div>
                </div> <!-- row -->
            </div> <!-- container -->
        </div> <!-- footer copyright -->
    </footer>
    <!--====== FOOTER PART ENDS ======-->
    <!--====== BACK TOP TOP PART START ======-->
    <a href="#" class="back-to-top"><i class="lni-chevron-up"></i></a>
    <!--====== BACK TOP TOP PART ENDS ======-->
    <!--====== jquery js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/vendor/modernizr-3.6.0.min.js"></script>
    <script src="/assets/website/js/frontend/surfboardnode/vendor/jquery-1.12.4.min.js"></script>
    <!--====== Bootstrap js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/bootstrap.min.js"></script>
    <script src="/assets/website/js/frontend/surfboardnode/popper.min.js"></script>
    <!--====== Images Loaded js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/imagesloaded.pkgd.min.js"></script>
    <!--====== Scrolling Nav js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/jquery.easing.min.js"></script>
    <script src="/assets/website/js/frontend/surfboardnode/scrolling-nav.js"></script>
    <!--====== Slick js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/slick.min.js"></script>
    <!--====== Main js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/main.js"></script>
    <script src="https://www.freeclashnode.com/assets/js/frontend/invite-url.js"></script>
    <script src="/assets/website/js/frontend/G.js"></script>
</body>

</html>